Skip to content

Dates: Accept ISO-8601 format, and use UTC milliseconds as the backend#1194

Merged
alexcjohnson merged 12 commits into
masterfrom
dates-utc-backend
Nov 25, 2016
Merged

Dates: Accept ISO-8601 format, and use UTC milliseconds as the backend#1194
alexcjohnson merged 12 commits into
masterfrom
dates-utc-backend

Conversation

@alexcjohnson

Copy link
Copy Markdown
Collaborator

First part: ISO-8601:

fixes #1003

For simplicity, I ended up separately allowing the date/time separator to be space, t, or T, and a timezone spec at the end - ie timezones are now accepted for our normal space-separated format too.

Also @etpinard a perf note - I switched from the manual string chopping we had before to a regexp-based conversion. When I originally wrote this converter a few years ago it was clearly faster to do it manually, but now either because our patterns have gotten more complicated, or browsers have improved their regexp engines, it's faster this way. It's also a lot shorter code-wise (though I wouldn't exactly call it nicer to look at, with that mile-long regexp!)

On Chrome, the old way (extended to ISO-8601) was taking ~2microsec per conversion, the new way is ~1.3microsec. FF is quite a bit slower at both versions, but the regexp is faster there too: ~6.8microsec vs ~10.7microsec.

The rest: use UTC milliseconds as the back end:

Changes our internal date linearization to use UTC rather than local milliseconds. Every day on a Plotly graph will now be 24 hours long, with no daylight shifts.

Note that for backward compatibility I still have us treat millisecond values (in ranges etc) as they were calculated previously, in local time, and shift them to UTC. I do the same thing with js date objects, on the theory that users generally construct these by using new Date(y, m, d, H, M, S, ms) with the date/time components they expect to see on the final graph.

If and when we add support for explicit timezone settings, we can do smarter things for users who specify a timezone, but I think this should remain the default behavior.

Fixes #171 and #811

This PR supersedes #1158 and #1172

@alexcjohnson alexcjohnson added status: reviewable bug something broken feature something new labels Nov 24, 2016
@etpinard etpinard added this to the v1.21.0 milestone Nov 24, 2016
Comment thread src/lib/dates.js
var ONEMIN = constants.ONEMIN;
var ONESEC = constants.ONESEC;

var DATETIME_REGEXP = /^\s*(-?\d\d\d\d|\d\d)(-(0?[1-9]|1[012])(-([0-3]?\d)([ Tt]([01]?\d|2[0-3])(:([0-5]\d)(:([0-5]\d(\.\d+)?))?(Z|z|[+\-]\d\d:?\d\d)?)?)?)?)?\s*$/m;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you cook this up yourself or find from a google search? If the latter, can you paste the reference above?

'2015-01-01 12:00:60', '2015-01-01 12:00:-1', '2015-01-01 12:00:001', '2015-01-01 12:00:1' // bad second
'2015-01-01 12:00:60', '2015-01-01 12:00:-1', '2015-01-01 12:00:001', '2015-01-01 12:00:1', // bad second
'2015-01-01T', '2015-01-01TT12:34', // bad ISO separators
'2015-01-01Z', '2015-01-01T12Z', '2015-01-01T12:34Z05:00', '2015-01-01 12:34+500', '2015-01-01 12:34-5:00' // bad TZ info

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good.

new Date(),
new Date(-9999, 0, 1),
new Date(9999, 11, 31, 23, 59, 59, 999)
new Date(-9999, 0, 3), // we lose one day of range +/- tzoffset this way

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for that comment

xaxis: {
type: 'date',
range: ['2000-01-01', (new Date(2000, 1, 2)).getTime()]
range: ['2000-01-01', '2000-02-02']

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@etpinard etpinard left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good 💃

I'm thinking it would be nice to make http://codepen.io/plotly/pen/grdEaN (from #811) part of our image tests. Non-blocking if you feel that the jasmine tests are sufficient.

@etpinard

Copy link
Copy Markdown
Contributor

... and don't forget to close #171 and #811 after merging.

"xaxis4": {"anchor": "y4"},
"xaxis5": {"anchor": "y5"},
"xaxis6": {"anchor": "y6"},
"xaxis7": {"anchor": "y7"}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@etpinard good point about including the UTC behavior in the mocks. I replaced the simple date_axes.json with this one that includes tick scales all the way from full years to partial seconds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug something broken feature something new

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support ISO 8601 timestamps Plotting issues with daylight savings time

2 participants